#!/bin/bash
# Script to install chaincode onto a peer node
{% include "envsetting.j2" %}
{% if CC_LANGUAGE == 'go' %}
{% if fabric.goproxy is defined %}
  go env -w GOPROXY={{ fabric.goproxy }}
{% endif %}
cd /opt/gopath/src/github.com/chaincode/{{ CC_NAME }}
if [ -f 'go/go.mod' ] && [ ! -d 'go/vendor' ]; then
  cd go
  export GO111MODULE=on
{% if fabric.release is version('1.4.3','<=') and fabric.release != '1.4' %}
  export GOCACHE=on
{% endif %}
  go mod vendor
  export GO111MODULE=off
  cd -
fi
peer chaincode install --tls -l golang -v {{ CC_VERSION }} -n {{ CC_NAME }} \
  -p github.com/chaincode/{{ CC_NAME }}/go
{% elif CC_LANGUAGE == 'node' %}
peer chaincode install --tls -l node -v {{ CC_VERSION }} -n {{ CC_NAME }} \
  -p /opt/gopath/src/github.com/chaincode/{{ CC_NAME }}/node
{% elif CC_LANGUAGE == 'java' %}
peer chaincode install --tls -l java -v {{ CC_VERSION }} -n {{ CC_NAME }} \
  -p /opt/gopath/src/github.com/chaincode/{{ CC_NAME }}/java
{% endif %}
